package com.siblings.loan.ui.launch

import android.view.View
import com.lib.base.utils.TitleBarUtil
import com.siblings.loan.utils.helper.SibAnalysisHelper
import com.siblings.loan.utils.helper.TestDataLibInit
import com.siblings.loan.databinding.ActLaunchBinding
import com.siblings.loan.http.HttpHelper
import com.siblings.loan.ui.tab.act.SibMainAct
import com.siblings.loan.ui.launch.impl.SibLaunchPresenterImpl
import com.siblings.loan.ui.launch.view.ISibLaunchView
import com.siblings.loan.ui.permission.SibPermissionAct
import com.siblings.loan.ui.user.act.SibLoginAct
import com.siblings.loan.utils.event.SibEventType
import com.siblings.loan.utils.helper.SharedHelper
import com.siblings.mvp.MvpAct

/**
 * SiblingsLoan
 * @Author wwdeng
 * @CreateTime: 2024/7/3 15:39
 * @Annotation：启动页
 */
class SibLaunchAct : MvpAct<ISibLaunchView, SibLaunchPresenterImpl>(),ISibLaunchView {
    lateinit var binding: ActLaunchBinding

    override fun createMvpPresenter(): SibLaunchPresenterImpl {
        return SibLaunchPresenterImpl(this)
    }

    override fun getSibRootView(): View {
        binding = ActLaunchBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initSibView() {
        TitleBarUtil.setStatusBarLightMode(this, false)
    }

    override fun initSibListener() {
    }

    override fun initSibData() {
        mvpPresenter.loadSibTimeZoneAction()
    }

    /**
     * 地区转发成功
     */
    override fun showSibTimeZoneRequestData(timeZone: String, zoneCode: String) {
        //保存转发地区
        SharedHelper.saveSibSPData(SharedHelper.SIB_SPKEY.SIBLINGS_TIMEZONE,timeZone)
        //保存转发地区 区号
        SharedHelper.saveSibSPData(SharedHelper.SIB_SPKEY.SIBLINGS_TIMEZONE_CODE,zoneCode)
        //初始化analysis lib 赋值 转发地区
        SibAnalysisHelper.initAnalysisLibAtZoneSuccess()
        //初始化 data lib
        TestDataLibInit.initDataLibAtZoneSuccess()
        //添加埋点
        HttpHelper.addSibEventAction(SibEventType.PAGE.SIB_PAGE_LAUNCH_START,"")
        mvpPresenter.loadSibCommonConfigAction()
    }

    /**
     * 进入权限页
     */
    override fun showSibPermissionPage() {
        onIntent(SibPermissionAct::class.java)
        finish()
    }

    /**
     * 进入登录页
     */
    override fun showSibLoginPage() {
        onIntent(SibLoginAct::class.java)
        finish()
    }

    /**
     * 进入主页
     */
    override fun showSibMainPage() {
        onIntent(SibMainAct::class.java)
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()
        HttpHelper.addSibEventAction(SibEventType.PAGE.SIB_PAGE_LAUNCH_END,"")
    }
}